package com.bocai.kelalacar.ui.car.order.act;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.kelalacar.R;
import com.bocai.kelalacar.base.BaseActivity;
import com.bocai.kelalacar.ui.car.order.frag.MyEmptyInformationFrag;
import com.bocai.kelalacar.ui.car.order.frag.RushOrderFrag;
import com.flyco.tablayout.SlidingTabLayout;

import butterknife.BindView;

/**
 * Created by yuanfei on 2017/6/21.
 */

public class MyCarOrderActivity extends BaseActivity {
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.right_btn)
    Button rightBtn;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tab_layout)
    SlidingTabLayout tabLayout;
    @BindView(R.id.vp_order)
    ViewPager vpOrder;
    private final String[] mFragmentTitles = {"我的空车信息", "抢单"};
    @BindView(R.id.ll_back)
    LinearLayout llBack;

    @Override
    public int getLayoutId() {
        return R.layout.act_my_car_order;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {

        initToolbar("我的行程");
        initBack(imgBack,llBack);
        vpOrder.setAdapter(new Adapter(getSupportFragmentManager()));
        vpOrder.setOffscreenPageLimit(2);

        tabLayout.setViewPager(vpOrder,mFragmentTitles);

    }
    class Adapter extends FragmentPagerAdapter {
        private final Fragment[] mFragments = new Fragment[2];


        public Adapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            Fragment fragment = mFragments[position];
            if (fragment == null) {
                if (position == 0) {
                    fragment = new MyEmptyInformationFrag();
                } else if (position == 1) {
                    fragment = new RushOrderFrag();
                }

                mFragments[position] = fragment;
            }
            return fragment;
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {

            return mFragmentTitles[position];
        }
    }
}
